var pro_load_page = 2,pro_load_flag = true;
footer.init();
header.init('店铺管理');
window.sessionStorage.setItem('material-status',3);
var material = {
	init :　function(url,data,stauts){
		app.ajax
		(
			url,
			data,
			function(res){
				if(res.code == 200){
					res.status = stauts;
					app.tpl($('.material'),'tpl-material',res);
					fomartImg();
					echo.init();
				}else{
					layer.msg('网络繁忙，请稍候再试');
				}
			}
		);
	},
	loadMore :function(url,data,status){
		var listLoadingEmpty = '<div style="height:3rem;line-height:3rem;text-align:center;font-size:1.2rem;" class="no-more">努力加载中~<div>';
   		$('.material').append(listLoadingEmpty);
		pro_load_flag = false;
		app.ajax(
			url,
			data,
			function(res){
				$('.material .no-more').remove();
				if(res.code == 200){
					console.log(status);
						res.status = status;
						app.tpladd($('.material'),'tpl-material',res);		
						fomartImg();
						echo.init();
						pro_load_page++;
						pro_load_flag = true;
					//page++;
				}else{	
						pro_load_flag = false;
						var listLoadingEmpty = '<div style="height:3rem;line-height:3rem;text-align:center;font-size:1.2rem;">没有更多数据了~<div>';
						$('.material').append(listLoadingEmpty);
				}
			});	
	}
}


material.init('/Member/ShareSpecials/p_list',{page :1 },3);

window.onload = function(){

	if($('header').html()){
		$('.material').css('marginTop','7.34rem');
	}
	
	$('.material-nav li:first h2').addClass('font-active');
	$('.material-nav li:first i').show();
	//收益
	$('body').on('click','.shop-profit',function(){//我的收益
		app.open('shop.profit.html','shop_profit',{},window.location.href,document.body.scrollTop);
	});
	
	$('body').on('click','.material-nav li',function(){
		$('.material-nav li h2').removeClass('font-active');
		$('.material-nav li i').hide();
		$(this).find('h2').addClass('font-active');
		$(this).find('i').show();
		var status = $(this).attr('data-status');
		var url='';
		window.sessionStorage.setItem('material-status',status);
		if(status == 1){
			url = '/Member/ShareSpecials/index';
			window.sessionStorage.setItem('material-url',url);
		}else if(status == 2){
			url = '/Member/ShareSpecials/z_list';
			window.sessionStorage.setItem('material-url',url);
		}else{
			url = '/Member/ShareSpecials/p_list';
			window.sessionStorage.setItem('material-url',url);
		}
		$('.promp-order').remove();
		material.init(url,{page :1 },status);
	});
	
	$(window).scroll(function(){
		// 当滚动到距底部以上200像素
		var offset = $(".material").offset(),
		dataType = 3,
		url= '',
		data = {};
		var documentHeight = offset.top + $(".material").height();
		if (documentHeight - $(this).scrollTop() - $(this).height()<100){
				if(window.sessionStorage.getItem('material-status')){
					 dataType=window.sessionStorage.getItem('material-status');
					 url = window.sessionStorage.getItem('material-url');
				}
				data = {
					page :pro_load_page
				};
			pro_load_flag && material.loadMore(url,data,dataType);
		}
	});
}

function fomartImg(){
	$("li.mR3.mT2").css("height",$("li.mR3.mT2:eq(1)").width());
}
